package com.boco.wmworkflow.statistic.attemp.action;

import com.boco.transnms.client.model.base.BoCmdFactory;
import org.apache.struts.util.LabelValueBean;
import com.boco.webmaster.base.SessionManager;
import javax.servlet.http.HttpServletRequest;
import com.boco.webmaster.security.validate.action.JspCheckUserHelper;
import java.util.ArrayList;
import com.boco.transnms.common.dto.SysUser;
import java.util.List;
import com.boco.transnms.common.dto.base.DataObjectList;
import com.boco.transnms.server.bo.helper.workflow.AttempAppSheetBOHelper;
import com.boco.transnms.client.model.base.IBoCommand;
import com.boco.transnms.common.dto.Organization;
import com.boco.transnms.common.dto.base.BoActionContext;

public class AttempQueryJspHelper {
    public AttempQueryJspHelper() {
    }
    public static void initSendUser(HttpServletRequest request) throws Exception {
           String relateCuid = JspCheckUserHelper.getUserContext(request).getRelatedOrganizationCuid();
           IBoCommand cmd = null;
           cmd = BoCmdFactory.getInstance().createBoCmd(AttempAppSheetBOHelper.ActionName.getSendUser, new Object[] {new BoActionContext(),relateCuid});
           DataObjectList dbos = (DataObjectList) cmd.exec();
           List userList = new ArrayList();
           for (int i = 0; i < dbos.size(); i++) {
               SysUser user = (SysUser)dbos.get(i);
               String senduserName = user.getTrueName();
               if(senduserName.equals(""))
               {
                  senduserName = user.getUserName();
               }
               String senduserCuid = user.getCuid();
              userList.add(new LabelValueBean(senduserName,senduserCuid));
               //DVList.add("addRow(\"" + dv.getCuid() + "\",\"" + value + "\"," + (i + 1) + ")");
           }
           SessionManager.getInstance().saveQueryAttr(request, "userList", userList);
   }
   public static void initGiveUser(HttpServletRequest request) throws Exception {
           String relateCuid = JspCheckUserHelper.getUserContext(request).getRelatedOrganizationCuid();
           IBoCommand cmd = null;
           cmd = BoCmdFactory.getInstance().createBoCmd(AttempAppSheetBOHelper.ActionName.getGiveUser, new Object[] {new BoActionContext(),relateCuid});
           DataObjectList dbos = (DataObjectList) cmd.exec();
           List userList = new ArrayList();
           for (int i = 0; i < dbos.size(); i++) {
               SysUser user = (SysUser)dbos.get(i);
               String gsenduserName = user.getTrueName();
               if(gsenduserName.equals("admin")||user.getUserName().equals("admin"))
               {
                  return;
               }
               if(gsenduserName.equals(""))
               {
                  gsenduserName = user.getUserName();
               }

               String gsenduserCuid = user.getCuid();
              userList.add(new LabelValueBean(gsenduserName,gsenduserCuid));
               //DVList.add("addRow(\"" + dv.getCuid() + "\",\"" + value + "\"," + (i + 1) + ")");
           }
           SessionManager.getInstance().saveQueryAttr(request, "guserList", userList);
   }
   public static void initOrg(HttpServletRequest request) {
          IBoCommand cmd = null;
          cmd = BoCmdFactory.getInstance().createBoCmd(AttempAppSheetBOHelper.ActionName.getAllOrg, new Object[] {new BoActionContext()});
          DataObjectList dbos = (DataObjectList) cmd.exec();
          List userList = new ArrayList();
          for (int i = 0; i < dbos.size(); i++) {
              Organization user = (Organization)dbos.get(i);
              String OName = user.getOrgName();
              String OCuid = user.getCuid();
             userList.add(new LabelValueBean(OName,OCuid));
              //DVList.add("addRow(\"" + dv.getCuid() + "\",\"" + value + "\"," + (i + 1) + ")");
          }
          SessionManager.getInstance().saveQueryAttr(request, "oList", userList);
  }


}
